let path = require('path');
const webpack=require("webpack")
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');

module.exports = {
    entry: './src/index.js',
    output: {
        filename: 'js/[name].[chunkhash:8].js',
        path: path.resolve(__dirname, 'dist'),
        publicPath: '/'   
    },
    devtool: 'eval-source-map',
    module: {
        rules: [
            {
                test: /\.(scss|css)$/,
                use: ExtractTextPlugin.extract({
                    fallback: 'style-loader',
                    use: ['css-loader', 'sass-loader']
                }),
                exclude: '/node_modules/'
            },
            {
                test: /\.(js|jsx)$/,
                use: {
                    loader: "babel-loader",
                    options: {
                        presets: [
                            "es2015", "react"
                        ],
                        plugins: [
                            ["import", { libraryName: "antd", style: "css" }]
                        ]
                    }
                },
                exclude: '/node_modules/'
            },
            {
                test: /\.(png|svg|jpg|gif)$/,
                use: [
                    'file-loader'
                ],
                exclude: '/node_modules/'
            },{
                test: /\.json$/,
                loader: "json-loader"
            }
        ]
    },

    plugins: [
        new ExtractTextPlugin('css/[name].[chunkhash:8].css'),
        new HtmlWebpackPlugin({
            template: 'index.template.html'
        }),
    ],

    devServer: {
        contentBase: "./build",//本地服务器所加载的页面所在的目录
        historyApiFallback: true,//不跳转
        inline: true//实时刷新
    } 
}